package org.fage.semples.dao;
   

import java.util.List;

import org.fage.semples.model.ExamUserRole;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ExamUserRoleHiberanteDAOImpI extends BaseHibernateDAO<ExamUserRole> implements ExamUserRoleHiberanteDAO {

	@Override
	public ExamUserRole getExamUserRoleById(String userId) {
		return this.queryForObject("FROM ExamUserRole AS r WHERE r.examUser.userId=?", new Object[]{userId});
	}
	
	public List<ExamUserRole> findAllStudent25(){
		return this.queryForList("FROM ExamUserRole AS r WHERE r.examRole.name=?", new Object[]{"25"});
	}

	@Override
	public void addExamRole(int roleId) {
		String sql = "insert into exam_role(role_id,name) values(:roleId, :name)";
		this.createSqlQuery(sql).setInteger("roleId", roleId).setString("name", "25").executeUpdate();
		
	}

	@Override
	public void addExamUserRole(int roleId, String userId) {
		String sql = "insert into exam_user_role(role_id,user_id) values(:roleId, :userId)";
		this.createSqlQuery(sql).setInteger("roleId", roleId).setString("userId", userId).executeUpdate();
	}
	@Override
	public void deleteExamRole(int roleId) {
		String sql = "delete exam_role from exam_role where role_id = :roleId";
		this.createSqlQuery(sql).setInteger("roleId", roleId).executeUpdate();
		
	}

	@Override
	public void deleteExamUserRole(int roleId, String userId) {
		String sql = "delete exam_user_role from exam_user_role where role_id = :roleId and user_id = :userId";
		this.createSqlQuery(sql).setInteger("roleId", roleId).setString("userId", userId).executeUpdate();
	}
}
